const crypto = require("utils/test");
App({
  onLaunch() {
    if(!wx.cloud){
      console.error("版本过低")
    }else{
      wx.cloud.init({
        env:'coffee-env-223fsakjys030fa8c7',
        traceUser:true,
      })
    }
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 登录
    var that = this;
    wx.login({
      success(res) {
        if(res.code){
          console.log(res.code);
          wx.request({
            url: 'http://localhost:9876/send',
            method:'POST',
            data: {
              code: res.code
            },
            header: {
              "Content-Type": "application/x-www-form-urlencoded" //POST方式是这个
            },
          });
        }
        else{
          console.log("Error: " + res.code);
        }
      }
    })
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    const systemInfo = wx.getSystemInfoSync(); //获取系统信息
    const menuInfo = wx.getMenuButtonBoundingClientRect(); // 获取胶囊按钮的信息
    this.globalData.windowWidth=systemInfo.windowWidth;
    this.globalData.menuHeight = menuInfo.height; // 获取胶囊按钮的高
    this.globalData.statusBarHeight = systemInfo.statusBarHeight; // 获取状态栏的高
    this.globalData.menuRight = menuInfo.right; // 获取胶囊按钮的距离屏幕最右边的距离（此处用于设置导航栏左侧距离屏幕的距离）
    this.globalData.navBarHeight = (menuInfo.top - systemInfo.statusBarHeight) * 2 + menuInfo.height; // 计算出导航栏的高度
    this.globalData.nowTime=new Date(Date.parse(new Date())+ 60*60*1000*8).toISOString();
    this.globalData.windowHeight=systemInfo.windowHeight;
    this.globalData.ScreenHeight=systemInfo.screenHeight;
  },
  globalData: {
    windowWidth:0,//屏幕宽度
    windowHeight:0,//内容高度
    ScreenHeight:0,//屏幕高度
    navBarHeight:0,// 导航栏高度
    menuHeight:0,//胶囊按钮 高度
    statusBarHeight:0,//状态栏高度
    menuRight:0,//胶囊按钮 距离屏幕右边的距离
    userInfo: null,
    nowTime:null,
    skipPage:0,
    openId:null,
    userCardChangeFlag:0,
    userDataChangeFlag:0,
    userOrdersChangeFlag:0,
    userCouplesChangeFlag:0,
  }
})
